<?php
/**
 * Created by PhpStorm.
 * User: Digvijay
 * Date: 3/17/14
 * Time: 1:03 PM
 */

use Doctrine\ORM\Tools\SchemaTool;

class Schema extends CI_Controller {
    public $em;

    function __construct() {
        parent::__construct();
        $this->em = $this->doctrine->em;
    }

    function index() {
        try {
            $schemaTool = new SchemaTool($this->em);
            $classes = $this->em->getMetadataFactory()->getAllMetadata();
            $schemaTool->updateSchema($classes);

            $notification = new Notification();
            $this->em->persist($notification);
            $this->em->flush();

            $specialOffer = new Specialoffer();
            $specialOffer->setDescription(" ");
            $specialOffer->setImage("special-offer-1.jpg");

            $this->em->persist($specialOffer);
            $this->em->flush();

            $specialOffer = new Specialoffer();
            $specialOffer->setDescription(" ");
            $specialOffer->setImage("special-offer-2.jpg");

            $this->em->persist($specialOffer);
            $this->em->flush();

            $specialOffer = new Specialoffer();
            $specialOffer->setDescription(" ");
            $specialOffer->setImage("special-offer-3.jpg");

            $this->em->persist($specialOffer);
            $this->em->flush();

            $systemConfig = new Systemconfig();
            $systemConfig->setProperty(Systemconfig::SPECIAL_OFFER);
            $systemConfig->setValue("true");

            $systemConfig = new Systemconfig();
            $systemConfig->setProperty(Systemconfig::CRON_ORDER_CANCEL_ENABLE);
            $systemConfig->setValue("true");

            $systemConfig = new Systemconfig();
            $systemConfig->setProperty(Systemconfig::CRON_ORDER_CANCEL_HOUR);
            $systemConfig->setValue("48");

            echo "<div style='margin:10% 40% 10% 40%;height:10%;padding:5% 5% 5% 5%;background-color:gainsboro'>";
            echo "<h4 align='center'>Schema Updated</h4>";
            echo "<div>";
        } catch (Exception $e) {
            echo $e->getMessage();
        }
    }

    function createUser() {
        $user = new User();
        $user->setFirstName("Digvijay");
        $user->setLastName("Mohite");
        $user->setUsername("digvijay");
        $user->setPassword("digvijay");
        $user->setEmail("digvijaymohite27@gmail.com");
        $user->setRole("Administrator");
        $this->em->persist($user);
        $this->em->flush();
        echo "User Create";
    }
}